package 集合框架;

import java.io.File;

    public class TraversalFile {
        public static void main(String[] args) {
            File file = new File("c://Windows");
            File[] files = file.listFiles();
            long max = files[0].length();
            long min = files[0].length();
            File maxFile = files[0];
            File minFile = files[0];
            for (File f : files) {
                if (f.length() != 0) {
                    if (f.length() > max) {
                        max = f.length();
                        maxFile = f;
                    }
                    if (f.length() < min) {
                        min = f.length();
                        minFile = f;
                    }
                }
            }
            System.out.println("最大文件为：" + maxFile.getName() + " 大小为：" + max);
            System.out.println("最小文件为：" + minFile.getName() + "大小为：" + min);
        }
    }
